<?php

// Change the following variables to connect to your mysql databse
$mydb_host = "localhost";
$mydb_user = "root";
$mydb_pass = "";
$mydb_name = "doue_net";


// Connection to the databse
mysql_connect($mydb_host,$mydb_user,$mydb_pass) or die(mysql_error());
mysql_select_db($mydb_name) or die(mysql_error());

 
// Create the tag array  with 50 records from the database,  all  modified during the last 2 days 
function tag_info() {
	$result = mysql_query("SELECT * FROM nuage WHERE date BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 2 DAY) AND CURDATE( ) ORDER BY count DESC LIMIT 50");
		while($row = mysql_fetch_array($result)) {
		$arr[$row['mot']] = $row['count'];
		}
	ksort($arr);
	return $arr;
}	

function tag_cloud() {
// Define the min and max size of the fonts 
	$min_size = 10;
	$max_size = 30;
	$tags = tag_info();
	$minimum_count = min(array_values($tags));
	$maximum_count = max(array_values($tags));
	$spread = $maximum_count - $minimum_count;
	if($spread == 0) {
		$spread = 1;
	}

$cloud_html = '';
$cloud_tags = array();

foreach ($tags as $tag => $count) {
	// My records have a + between each word, I'm removing these with the line below
	$tagshow = str_replace("+"," ",$tag);
	$size = $min_size + ($count - $minimum_count) * ($max_size - $min_size) / $spread;
	
	// create the html output - make sure to adapt tout you url
	$cloud_tags[] = '<div class="bg'. floor($size) . '"><a style="font-size: '. floor($size) . 'px'
	. '" class="tag_cloud'. floor($size) . '" href="www.doue.net?tag=' . $tag
	. '" title="\'' . $tag . '\' returned a count of ' . $count . '">'
	. htmlspecialchars(stripslashes($tagshow)).'<span class="countNUM">'." (".$count.")".'</span>'.'</a></div>';
}

$cloud_html = join("\n", $cloud_tags) . "\n";
return $cloud_html;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>Tag Cloud Projet de Tachun LIN</title>
	<meta name="keywords" content="download tag cloud free script" />
	<meta name="description" content="Design Tag cloud" />
    <link href="stylesheet/tagcloud2.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div class="around small">
	<!-- display the tag cloud -->	
		<div class="cloud">
			<?php print tag_cloud(); ?>
		</div></br>
	</div>
</body>
</html>